package de.muahd.saga.ui.springmvc.controller;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import de.muahd.saga.common.model.Customer;
import de.muahd.saga.services.core.api.CustomerService;

@Controller
@RequestMapping(value="/")
public class DefaultController {
	
	@Autowired
	private CustomerService customerService;
	
	@RequestMapping(value="/", method=RequestMethod.GET)
	public String testxy(Map<String, Object> model) {
		
		Customer customer = customerService.findByLastName("blablabla");
		
		if(customer == null) {
			customer = new Customer();
			customer.setFirstname("lalala");
			customer.setLastname("blablabla");
			
			customerService.saveCustomer(customer);
		} else {
			customer.setFirstname(customer.getFirstname() + "  fromDB");
		}
		
		model.put("customer", customer);
		
		return "welcome";
	}
	
}
